#+TITLE:   +rx/Emacs-Configuration
#+AUTHOR:  rxf4el
#+EMAIL:   rxf4el@pm.me
#+STARTUP: overview
---
* TABLE OF CONTENTS                                                   :TOC@4:
- [[#intro][INTRO]]
- [[#configuration][CONFIGURATION]]
  - [[#header][HEADER]]
  - [[#core-system][CORE SYSTEM]]
    - [[#paths][Paths]]
    - [[#package-manager][Package Manager]]
      - [[#straight][Straight]]
      - [[#leaf][Leaf]]
    - [[#garbage-collector][Garbage Collector]]
    - [[#saves][Saves]]
    - [[#async][Async]]
    - [[#persistent-data][Persistent Data]]
      - [[#cache][Cache]]
      - [[#scratch][Scratch]]
    - [[#default-settings][Default Settings]]
      - [[#secretel][Secret.el]]
      - [[#better-customs][Better Customs]]
      - [[#keybindings][Keybindings]]
      - [[#daemonserver][Daemon/Server]]
    - [[#aesthetics][Aesthetics]]
      - [[#cursor][Cursor]]
      - [[#fonts][Fonts]]
      - [[#icons][Icons]]
      - [[#modeline][Modeline]]
      - [[#themes][Themes]]
  - [[#modules][MODULES]]
    - [[#completions][Completions]]
      - [[#input-completion][Input Completion:]]
      - [[#text-completion][Text Completion:]]
    - [[#editor][Editor]]
      - [[#anzu][Anzu]]
      - [[#crux][Crux]]
      - [[#dired][Dired]]
      - [[#easy-kill][Easy-Kill]]
      - [[#editorconfig][EditorConfig]]
      - [[#environment][Environment]]
      - [[#expand-region][Expand-Region]]
      - [[#git][Git]]
      - [[#modal][Modal]]
      - [[#movetext][MoveText]]
      - [[#neotree][NeoTree]]
      - [[#parenthesis][Parenthesis:]]
      - [[#projects][Projects]]
      - [[#scroll][Scroll]]
      - [[#teminals][Teminals]]
      - [[#transient][Transient]]
      - [[#wich-key][Wich-Key]]
    - [[#window-manager][Window Manager]]
      - [[#dmenu][Dmenu]]
      - [[#exwm][Exwm]]
      - [[#moving-around][Moving Around]]
      - [[#resizing][Resizing]]
      - [[#shackle][Shackle]]
      - [[#splitting][Splitting]]
  - [[#code][CODE]]
    - [[#langs][Langs]]
      - [[#lisp][lisp]]
      - [[#webdev][webdev]]
      - [[#haskell][haskell]]
      - [[#lua][lua]]
      - [[#nix][nix]]
      - [[#python][python]]
      - [[#perl][perl]]
      - [[#r][r]]
    - [[#modes][Modes]]
      - [[#sh-script][sh-script]]
      - [[#csv][csv]]
      - [[#dhall][dhall]]
      - [[#json][json]]
      - [[#markdown][markdown]]
      - [[#yaml][yaml]]
    - [[#syntax][Syntax]]
      - [[#flymake][flymake]]
      - [[#flyspell][flyspell]]
  - [[#org][ORG]]
    - [[#org-mode][org-mode]]
    - [[#org-superstar][org-superstar]]
    - [[#org-toc][org-toc]]
  - [[#others][OTHERS]]
    - [[#academic][Academic]]
      - [[#export][Export]]
      - [[#presentation][Presentation]]
      - [[#references][References]]
    - [[#epubpdf][Epub/Pdf]]
    - [[#gkroam][GkRoam]]
    - [[#eww][Eww]]
  - [[#footer][FOOTER]]
- [[#references-1][REFERENCES]]
  - [[#literate][LITERATE]]
  - [[#modular][MODULAR]]
  - [[#single][SINGLE]]

* INTRO
After many attempts to create my own emacs configuration, i think now
i’m really on the right path to find myself into this world. I found
on ~Org~ literate config and [[https://github.com/conao3/leaf.el][Leaf.el]] by ~conao3~ the base i wanted to keep
myself really organized. Now i know everything about my config, even
though i have stolen many snips of code from others configuration and
adapt it to my workflow.
* CONFIGURATION
** HEADER
#+begin_src emacs-lisp :tangle yes
  ;;; config.el --- -*- lexical-binding: t -*-
#+end_src

** CORE SYSTEM
*** Paths
#+begin_src emacs-lisp :tangle yes
  ;; Make sure emacs always start at home
  ;; (cd "~/")
  (setq-default default-directory (concat (getenv "HOME") "/"))

  ;; Make sure we are on linux
  (defconst IS-LINUX (eq system-type 'gnu/linux))
  (defconst IS-MAC   (eq system-type 'darwin))

  ;; Default Directories
  (when IS-LINUX
    (defconst rx:emacs-d user-emacs-directory)
    (defconst rx:local-d    (concat rx:emacs-d ".local/"))
    (defconst rx:cache-d    (concat rx:local-d "cache/"))
    (defconst rx:temp-d     (concat rx:local-d "temp/"))
    (defconst rx:snippets-d (concat rx:emacs-d "straight/build/yasnippet-snippets/snippets/"))
    (defconst rx:projects-d (concat rx:cache-d "projects"))
    (defconst rx:org-d      (concat default-directory "Nextcloud/org/")))
#+end_src

*** Package Manager
**** Straight
#+begin_src emacs-lisp :tangle yes
  (custom-set-variables
   '(straight-vc-git-default-clone-depth 1)
   '(straight-use-package-by-default nil)
   '(straight-repository-branch "develop"))

  (defvar bootstrap-version)
  (let ((bootstrap-file
         (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
        (bootstrap-version 5))
    (unless (file-exists-p bootstrap-file)
      (with-current-buffer
          (url-retrieve-synchronously
           "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
           'silent 'inhibit-cookies)
        (goto-char (point-max))
        (eval-print-last-sexp)))
    (load bootstrap-file nil 'nomessage))

  (require 'straight-x)
#+end_src

**** Leaf
#+begin_src emacs-lisp :tangle yes
  (eval-and-compile
    (straight-use-package 'leaf-keywords)
    (require 'leaf)
    (require 'leaf-keywords)
    (leaf-keywords-init))
#+end_src

*** Garbage Collector
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'gcmh)
  ;; ------------------
  (leaf gcmh
    :doc "Enforce a sneaky Garbage Collection strategy to minimize GC"
    :url "https://gitlab.com/koral/gcmh"
    :init (gcmh-mode t))
#+end_src

*** Saves
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (require 'savehist)
  (require 'recentf)
  ;; ------------------
  (custom-set-variables
   ;; savehist
   '(savehist-file (concat rx:temp-d   "savehist"))
   '(savehist-save-minibuffer-history  t)
   '(savehist-additional-variables
     '(kill-ring search-ring regexp-search-ring))
   ;; recentf
   '(recentf-save-file                 (concat rx:temp-d "recentf"))
   '(recentf-exclude '("/tmp/" "/ssh:" "\\.?ido\\.last$" "\\.revive$" "/TAGS$"
                       "emacs\\.d/.local/cache/.+"))
   '(recentf-max-menu-items            0)
   '(recentf-max-saved-items           250)
   '(recentf-auto-cleanup              600)
   ;; backups
   '(bookmark-default-file             (concat rx:temp-d "bookmarks"))
   '(bookmark-save-flag                t)
   '(auto-save-list-file-name          (concat rx:temp-d "autosave"))
   '(auto-save-default                 nil)
   ;; In case I want to reactivate backup files
   '(make-backup-files                 nil)
   '(create-lockfiles                  nil)
   '(backup-directory-alist            `((".*" . ,(concat rx:temp-d "backup/"))))
   ;; Remember undo history
   '(undo-tree-auto-save-history       t)
   '(undo-tree-history-directory-alist `(("." . ,(concat rx:temp-d "undo/")))))

  (savehist-mode 1)
  (recentf-mode  1)

  ;; text properties severely bloat the history so delete them (courtesy of PythonNut)
  (defun unpropertize-savehist ()
    (mapc (lambda (list)
            (with-demoted-errors
                (when (boundp list)
                  (set list (mapcar #'substring-no-properties (eval list))))))
          '(kill-ring minibuffer-history helm-grep-history helm-ff-history file-name-history
                      read-expression-history extended-command-history)))
  (add-hook 'kill-emacs-hook    #'unpropertize-savehist)
  (add-hook 'savehist-save-hook #'unpropertize-savehist)
#+end_src

*** Async
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'async)
  ;; ------------------
  (leaf async
    :doc "Asynchronous processing in Emacs"
    :url "https://github.com/jwiegley/emacs-async"
    :commands (async-start
               async-start-process
               async-get
               async-wait
               async-inject-variables))
#+end_src

*** Persistent Data
**** Cache
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'persistent-soft)
  ;; ------------------
  (leaf persistent-soft
    :doc "Persistent storage for Emacs, returning nil on failure"
    :url "https://github.com/rolandwalker/persistent-soft"
    :require persistent-soft
    :commands (persistent-soft-store
               persistent-soft-fetch
               persistent-soft-exists-p
               persistent-soft-flush
               persistent-soft-location-readable
               persistent-soft-location-destroy)
    :custom
    (pcache-directory . rx:cache-d))
#+end_src

**** Scratch
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  ;; (straight-use-package 'persistent-scratch)
  ;; ------------------
  ;; (leaf persistent-scratch
  ;;   :doc "Preserves the state of scratch buffers accross Emacs sessions"
  ;;   :url "https://github.com/Fanael/persistent-scratch"
  ;;   :setq
  ;;   (persistent-scratch-setup-default . t))

  ;; Make some buffers immortal
  (defun +rx/immortal-buffers ()
    (if (or (eq (current-buffer) (get-buffer "*scratch*"))
            (eq (current-buffer) (get-buffer "*Messages*")))
        (progn (bury-buffer)
               nil)
      t))

  (add-hook 'kill-buffer-query-functions '+rx/immortal-buffers)
#+end_src

*** Default Settings
**** Secret.el
#+begin_src emacs-lisp :tangle yes
  ;; .secrets.el
  (defvar my/own-real-name   nil "My own real name to use.")
  (defvar my/own-email       nil "My own email to use.")
  (defvar my/own-nick        nil "My own nick to use.")
  (defvar my/own-passwd      nil "My own passwd to use.")

  (let ((secret.el (expand-file-name ".secret.el" user-emacs-directory)))
    (when (file-exists-p secret.el)
      (load-file secret.el)))
#+end_src

**** Better Customs
#+begin_src emacs-lisp :tangle yes
  ;; Save all interactive customization to a temp file, which is never loaded.
  ;; This means interactive customization is session-local. Only this init file persists sessions.
  (setq custom-file (make-temp-file ".custom.el"))

  ;; For my "settings" I prefer to use custom-set-variables, which does a bunch of neat stuff.
  ;; First, it calls a variable's "setter" function, if it has one.
  ;; Second, it can activate modes as well as set variables.
  ;; Third, it takes care of setting the default for buffer-local variables correctly.
  ;; https://with-emacs.com/posts/tutorials/almost-all-you-need-to-know-about-variables/#_user_options
  ;; https://old.reddit.com/r/emacs/comments/exnxha/withemacs_almost_all_you_need_to_know_about/fgadihl/
  (custom-set-variables
   '(ad-redefinition-action              'accept)
   '(compilation-always-kill             t)
   '(compilation-ask-about-save          nil)
   '(compilation-scroll-output           t)
   '(echo-keystrokes                     0.02)
   '(ediff-diff-options                  "-w")
   '(ediff-split-window-function         'split-window-horizontally)
   '(ediff-window-setup-function         'ediff-setup-windows-plain)
   '(enable-recursive-minibuffers        nil)
   '(history-length                      500)
   '(inhibit-startup-echo-area-message   "Let’s Hack!")
   '(inhibit-startup-screen              t)
   '(initial-major-mode                  'text-mode)
   '(major-mode                          'fundamental-mode)
   '(ring-bell-function                  'ignore)
   '(save-interprogram-paste-before-kill nil)
   '(sentence-end-double-space           nil)
   '(track-eol                           t)
   '(line-move-visual                    nil)
   '(require-final-newline               t)
   '(mouse-yank-at-point                 t)
   '(make-pointer-invisible              t)
   '(minibuffer-prompt-properties '(read-only t point-entered minibuffer-avoid-prompt face minibuffer-prompt))
   '(eval-expression-print-length        nil)
   '(eval-expression-print-level         nil)
   ;; UTF-8 please
   '(locale-coding-system                'utf-8)
   '(set-terminal-coding-system          'utf-8)
   '(set-keyboard-coding-system          'utf-8)
   '(set-selection-coding-system         'utf-8)
   '(prefer-coding-system                'utf-8)
   '(delete-selection-mode               t)
   ;; for Corfu
   '(tab-always-indent                   'complete)
   '(completion-cycle-threshold          3))

  ;; ‘y-or-n-p
  (fset 'yes-or-no-p 'y-or-n-p)

  ;; Allow some things that emacs would otherwise confirm.
  (dolist (cmd
           '(eval-expression
             downcase-region
             upcase-region
             narrow-to-region
             set-goal-column
             dired-find-alternate-file))
    (put cmd 'disabled nil))
#+end_src

**** Keybindings
#+begin_src emacs-lisp :tangle yes
  ;; Unset annoying keys
  (global-unset-key (kbd "C-z"))
  (global-unset-key (kbd "C-x C-z"))
  (global-unset-key (kbd "<kp-insert>"))
  (global-unset-key (kbd "<insert>"))

  ;; Set initial and usefull keybindings
  (let ((map global-map))
    (define-key map (kbd "<M-s-return>") 'newline-and-indent)
    (define-key map (kbd "<f5>")         'revert-buffer)
    (define-key map (kbd "C-+")          'text-scale-increase)
    (define-key map (kbd "C--")          'text-scale-decrease)
    (define-key map (kbd "C-x w k")      'kill-buffer-and-window))
#+end_src

**** Daemon/Server
#+begin_src emacs-lisp :tangle yes
  (leaf server
    :doc "Emacs server"
    :tag "built-in"
    :config
    (progn
      (unless (and (fboundp 'server-running-p)
                   (server-running-p))
        (server-start))))
#+end_src

*** Aesthetics
**** Cursor
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (custom-set-variables
   '(cursor-type          'box)
   '(mouse-avoidance-mode 'banish))

  (set-face-background 'mouse "#777777")
#+end_src

**** Fonts
***** Font Face
#+begin_src emacs-lisp :tangle yes
  (defvar +rx/font-name nil)
  (defvar +rx/font-size nil)

  (setq +rx/font-name "TerminessTTF Nerd Font Mono")
  (setq +rx/font-size 140)

  (when (find-font (font-spec :name +rx/font-name))
    (set-face-attribute 'default nil
                        :font   +rx/font-name
                        :height +rx/font-size
                        :width  'Regular))
#+end_src

***** Emojis
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'emojify)
  ;; ------------------
  (leaf emojify
    :doc "Emacs extension to display emojis"
    :url "https://github.com/iqbalansari/emacs-emojify"
    :if (window-system)
    :hook ((org-mode-hook
            text-mode-hook)))
#+end_src

**** Icons
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'all-the-icons)
  (straight-use-package 'all-the-icons-ibuffer)
  (straight-use-package 'all-the-icons-dired)
  ;; ------------------
  (leaf all-the-icons-ibuffer
    :doc "Display icons for all buffers in ibuffer"
    :url "https://github.com/seagle0128/all-the-icons-ibuffer"
    :init (all-the-icons-ibuffer-mode t)
    :custom
    (all-the-icons-ibuffer-icon-size           . 1.0)
    (all-the-icons-ibuffer-icon-v-adjust       . 0.0)
    (all-the-icons-ibuffer-human-readable-size . t))

  (leaf all-the-icons-dired
    :doc "This adds dired support to all-the-icon"
    :url "https://github.com/jtbm37/all-the-icons-dired"
    :hook (dired-mode-hook . all-the-icons-dired-mode))
#+end_src

**** Modeline
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'mood-line)
  ;; (straight-use-package 'keycast)
  ;; ------------------
  (leaf mood-line
    :doc "A minimal mode-line configuration"
    :url "https://github.com/jessiehildebrandt/mood-line"
    :init
    (progn
      (mood-line-mode    t)
      (display-time-mode t))
    :custom
    (display-time-24hr-format . t)
    (display-time-format      . "%H:%M - %d %B %Y"))

  (leaf keycast
    :doc ""
    :url ""
    :disabled t
    :init
    (progn
      (keycast-mode t)))
#+end_src

**** Themes
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package '(spacemacs-theme
                          :type git
                          :host github
                          :repo "nashamri/spacemacs-theme"))
  ;; ------------------
  (load-theme 'spacemacs-dark t)
#+end_src

** MODULES
*** Completions
**** Input Completion:
***** ibuffer
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  ;; ------------------
  (custom-set-variables
   '(ibuffer-show-empty-filter-groups nil)
   '(ibuffer-expert t)
   '(ibuffer-saved-filter-groups
     '(("default"
        ("EMACS CONFIG"
         (filename . ".emacs.d/config"))
        ("EMACS LISP"
         (mode . emacs-lisp-mode))
        ("DIRED"
         (mode . dired-mode))
        ("ORG"
         (mode . org-mode))
        ("WEBDEV"
         (or
          (mode . html-mode)
          (mode . css-mode)
          (mode . js-mode)
          (mode . ts-mode)))
        ("EPUB/PDF"
         (or
          (mode . pdf-view-mode)
          (mode . nov-mode)))
        ("EWW"
         (mode . eww-mode))
        ("HELM"
         (mode . helm-major-mode))
        ("HELP"
         (or
          (name . "\*Help\*")
          (name . "\*Apropos\*")
          (name . "\*info\*")
          (name . "\*Warnings\*")))
        ("SPECIAL BUFFERS"
         (or
          (name . "\*scratch\*")
          (name . "\*Messages\*")
          (name . "\*straight-process\*")
          (name . "\*direnv\*")))))))

  (add-hook 'ibuffer-mode-hook (lambda ()
                                  (ibuffer-auto-mode t)
                                  (ibuffer-switch-to-saved-filter-groups "default")))

  (define-key global-map (kbd "C-x C-b") 'ibuffer)
#+end_src

***** uniquify
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (require 'uniquify)
  ;; ------------------
  (custom-set-variables
   '(uniquify-buffer-name-style 'reverse)
   '(uniquify-separator " • ")
   '(uniquify-after-kill-buffer-p t)
   '(uniquify-ignore-buffers-re "^\\*"))
#+end_src

***** helm
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'helm)
  (straight-use-package 'helm-rg)
  ;; ------------------
  (leaf helm
    :doc "Emacs framework for incremental completions and narrowing selections"
    :url "https://github.com/emacs-helm/helm"
    :require (helm-config helm-bookmark helm-rg)
    :init
    (progn
      (helm-mode t)
      (helm-autoresize-mode t))
    :custom
    (helm-autoresize-max-height                . 30)
    (helm-autoresize-min-height                . 10)
    ;; Generic configuration.
    (helm-follow-mode-persistent               . t)
    (helm-reuse-last-window-split-state        . t)
    (helm-display-header-line                  . nil)
    (helm-findutils-search-full-path           . t)
    (helm-show-completion-display-function     . nil)
    (helm-completion-mode-string               . "")
    (helm-dwim-target                          . 'completion)
    (helm-echo-input-in-header-line            . t)
    (helm-use-frame-when-more-than-two-windows . nil)
    (helm-grep-save-buffer-name-no-confirm     . t)
    ;; Fuzzy everywhere
    (helm-M-x-fuzzy-match                      . t)
    (helm-apropos-fuzzy-match                  . t)
    (helm-buffers-fuzzy-matching               . t)
    (helm-completion-in-region-fuzzy-match     . t)
    (helm-eshell-fuzzy-match                   . t)
    (helm-imenu-fuzzy-match                    . t)
    (helm-locate-library-fuzzy-match           . t)
    (helm-recentf-fuzzy-match                  . t)
    (helm-scroll-amount                        . 8)
    (helm-split-window-in-side-p               . nil)
    ;; To prevent M-s f from directly going to symbol at point if in same buffer.
    (helm-imenu-execute-action-at-once-if-one  . nil)
    ;; https://github.com/emacs-helm/helm/issues/1910
    (helm-buffers-end-truncated-string         . "…")
    (helm-buffer-max-length                    . 22)
    ;; Default needs special font
    (helm-ff-cache-mode-lighter                . " ⚒")
    (helm-ff-keep-cached-candidates            . nil)
    (helm-window-show-buffers-function         . 'helm-window-mosaic-fn)
    (helm-window-prefer-horizontal-split       . t)
    ;; Make `helm-mini' almighty.
    (helm-mini-default-sources . `(helm-source-buffers-list
                                   helm-source-recentf
                                   ,(when (boundp 'helm-source-ls-git)
                                      'helm-source-ls-git)
                                   helm-source-bookmarks
                                   helm-source-bookmark-set
                                   helm-source-buffer-not-found))
    :config
    (add-to-list 'helm-sources-using-default-as-input 'helm-source-man-pages)
    (helm-top-poll-mode)
    ;; Fallback on 'find' if 'locate' is not available.
    (unless (executable-find "locate")
      (setq helm-locate-recursive-dirs-command "find %s -type d -regex .*%s.*$"))
    :bind
    (("C-x c"   . nil)
     ("C-c h"   . helm-command-prefix)
     ("C-x b"   . helm-mini)
     ("C-s"     . helm-occur)
     ("C-x C-f" . helm-find-files)
     ("M-x"     . helm-M-x)))
#+end_src

**** Text Completion:
***** corfu
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'corfu)
  (straight-use-package 'cape)
  ;; ------------------
  (leaf corfu
    :doc "Completion Overlay Region FUnction"
    :url "https://github.com/minad/corfu"
    :init
    (progn
      (global-corfu-mode t))
    :custom
    (completion-style         . '(basic))
    (corfu-echo-documentation . nil)
    (corfu-quit-at-boundary   . t)
    (corfu-quit-no-match      . t)
    (corfu-cycle              . t)
    (corfu-auto               . t)
    (corfu-auto-delay         . 0)
    (corfu-auto-prefix        . 0)
    (corfu-scroll-margin      . 5))

  (leaf cape
    :doc ""
    :url ""
    :config
    ;; Add `completion-at-point-functions', used by `completion-at-point'.
    (add-to-list 'completion-at-point-functions #'cape-dabbrev)
    (add-to-list 'completion-at-point-functions #'cape-file)
    ;;(add-to-list 'completion-at-point-functions #'cape-history)
    ;;(add-to-list 'completion-at-point-functions #'cape-keyword)
    ;;(add-to-list 'completion-at-point-functions #'cape-tex)
    ;;(add-to-list 'completion-at-point-functions #'cape-sgml)
    ;;(add-to-list 'completion-at-point-functions #'cape-rfc1345)
    ;;(add-to-list 'completion-at-point-functions #'cape-abbrev)
    ;;(add-to-list 'completion-at-point-functions #'cape-ispell)
    ;;(add-to-list 'completion-at-point-functions #'cape-dict)
    ;;(add-to-list 'completion-at-point-functions #'cape-symbol)
    ;;(add-to-list 'completion-at-point-functions #'cape-line)
    )
#+end_src

***** hippie-expand
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  ;; ------------------
  (leaf hippie-exp
    :doc ""
    :tag "built-in"
    :custom
    (hippie-expand-try-functions-list
     . '(yas-hippie-try-expand
         try-expand-all-abbrevs
         try-expand-dabbrev
         try-expand-dabbrev-visible
         try-completion
         try-expand-line
         try-expand-list
         try-complete-file-name
         try-complete-file-name-partially
         try-complete-lisp-symbol
         try-complete-lisp-symbol-partially))
    :bind ("M-/" . hippie-expand))
#+end_src

***** lsp
****** eglot
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'eglot)
  (straight-use-package '(eglot-lua
                          :type git
                          :host github
                          :repo "juergenhoetzel/eglot-lua"))
  ;; ------------------
  (leaf eglot
    :doc "Emacs LSP client that stays out of your way"
    :url "https://github.com/joaotavora/eglot"
    :after project
    :require eglot-lua
    :commands
    (eglot-ensure)
    :custom
    (eglot-stay-out-of                . '(flymake))
    (eglot-ignored-server-capabilites . '(:documentHighlightProvider))
    (eglot-sync-connect               . 1)
    (eglot-connect-timeout            . 10)
    (eglot-autoshutdown               . nil)
    (eglot-send-changes-idle-time     . 0.5)
    (eglot-auto-display-help-buffer   . nil)
    :config
    (progn
      ;;   (add-to-list 'eglot-server-programs
      ;;                '(rx-vue-mode . ("~/.npm/globals/bin/vls")))
      ;;   (add-to-list 'eglot-server-programs
      ;;                '(purescript-mode
      ;;                  . ("purescript-language-server" "--stdio")))
      ;; (add-to-list 'eglot-server-programs
      ;;              '(lua-mode . ("lua-language-server")))
      (add-to-list 'eglot-server-programs
                   '(lua-mode . ("lua-lsp"))))
    :bind
    (:eglot-mode-map
     ("C-c l r" . eglot-rename)
     ("C-c l o" . eglot-code-action-organize-imports)
     ("C-c l h" . eldoc)
     ("<f6>"    . xref-find-definitions)))
#+end_src
      
***** snippets
****** skeleton
#+begin_src emacs-lisp :tangle no
  ;; ------------------
  ;; ------------------
  (leaf skeleton
    :doc ""
    :tag "built-in"
    :require init-skeletons)
#+end_src

****** yasnippet
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'yasnippet)
  (straight-use-package 'yasnippet-snippets)
  ;; ------------------
  (leaf yasnippet
    :doc "YASnippet is a template system for Emacs"
    :url "https://github.com/joaotavora/yasnippet"
    :require (yasnippet-snippets)
    :custom (yas-snippet-dirs . '(rx:snippets-d))
    :init
    (progn
      (yas-global-mode t)
      (let ((inhibit-message t))
        (yas-reload-all))))
#+end_src

*** Editor
**** Anzu
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'anzu)
  ;; ------------------
  (leaf anzu
    :doc "Emacs port of anzu.vim"
    :url "https://github.com/cedricporter/emacs-anzu"
    :init (global-anzu-mode t)
    :custom
    (anzu-modelighter                 . "")
    (anzu-deactivate-region           . t)
    (anzu-search-threshold            . 1000)
    (anzu-replace-threshold           . 50)
    (anzu-replace-to-string-separator . " => ")
    :bind
    (("C-c a q" . anzu-query-replace)
     ("C-c a r" . anzu-query-replace-regexp)
     ("C-c a c" . anzu-query-replace-at-cursor)))
#+end_src

**** Crux
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'crux)
  ;; ------------------
  (leaf crux
    :doc "A Collection of Ridiculously Useful eXtensions for Emacs"
    :url "https://github.com/bbatsov/crux"
    :config
    (progn
      (crux-with-region-or-buffer indent-region)
      (crux-with-region-or-buffer untabify)
      (crux-with-region-or-point-to-eol kill-ring-save)
      (defalias 'rename-file-and-buffer 'crux-rename-file-and-buffer))
    :bind
    (("C-a"     . crux-move-beginning-of-line)
     ("C-x 4 t" . crux-transpose-windows)
     ("C-k"     . crux-smart-kill-line)
     ("C-c c ;" . crux-duplicate-and-comment-current-line-or-region)
     ("C-c c c" . crux-cleanup-buffer-or-region)
     ("C-c c d" . crux-duplicate-current-line-or-region)
     ("C-c c f" . crux-recentf-find-file)
     ("C-c c k" . crux-kill-other-buffers)
     ("C-c c r" . crux-reopen-as-root-mode)
     ("C-c c t" . crux-visit-term-buffer)
     ("C-c c o" . crux-smart-open-line)
     ("C-c c a" . crux-smart-open-line-above)))
#+end_src

**** Dired
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'dired-subtree)
  (straight-use-package 'diredfl)
  ;; ------------------
  (leaf dired
    :doc "Who needs a filemanager"
    :tag "built-in"
    :require (dired-subtree diredfl)
    :hook (dired-mode-hook . dired-hide-details-mode)
    :custom
    (dired-listing-switches        . "-lGhA1vDpX --group-directories-first")
    (dired-recursive-copies        . 'always)
    (dired-recursive-deletes       . 'always)
    (delete-by-moving-to-trash     . t)
    (dired-dwim-target             . t)
    (dired-subtree-use-backgrounds . nil)
    :config
    (progn
      (define-key dired-mode-map "b" (lambda ()
                                       (interactive)
                                       (find-alternate-file ".."))))
    :bind
    (:dired-mode-map
     ("<tab>"   . dired-subtree-toggle)
     ("<C-tab>" . dired-subtree-cycle)
     ("w"       . wdired-change-to-wdired-mode)
     ("<M-RET>" . dired-open-file)))

  ;; (defun dired-open-file ()
  ;;   "In dired, open the file named on this line."
  ;;   (interactive)
  ;;   (let* ((file (dired-get-filename nil t)))
  ;;     (message "Opening %s..." file)
  ;;     (call-process "xdg-open" nil 0 nil file)
  ;;     (message "Opening %s done" file)))

  (defun dired-open-file ()
    (interactive)
    (setq file (dired-get-file-for-visit))
    (setq ext (file-name-extension file))
    (cond ((string= ext "pdf")
           ;; shell-quote-argument escapes white spaces on the file name
           (async-shell-command (concat "zathura " (shell-quote-argument file))))
          ((string= ext "epub")
           (async-shell-command (concat "zathura " (shell-quote-argument file))))
          (t (dired-find-file))))
#+end_src

**** Easy-Kill
#+begin_src emacs-lisp :tangle no
  ;; ------------------
  (straight-use-package 'easy-kill)
  ;; ------------------
  (leaf easy-kill
    :doc ""
    :url ""
    :bind
    (([remap kill-ring-save] . easy-kill)
     ([remap mark-sexp] . easy-mark)))
#+end_src

**** EditorConfig
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'editorconfig)
  ;; ------------------
#+end_src

**** Environment
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'direnv)
  (straight-use-package 'exec-path-from-shell)
  ;; ------------------
  (leaf direnv
    :doc "direnv integration for emacs"
    :url "https://github.com/wbolster/emacs-direnv"
    :init (direnv-mode t)
    :custom
    (direnv-always-show-summary   . nil)
    (direnv-show-paths-in-summary . nil))

  (leaf exec-path-from-shell
    :doc "A GNU Emacs library to ensure environment variables inside Emacs"
    :url "https://github.com/purcell/exec-path-from-shell"
    :custom
    (exec-path-from-shell-variables
     . '("PATH"
         "MANPATH"
         "NIX_PATH"
         "NIX_SSL_CERT_FILE")))
#+end_src

**** Expand-Region
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'expand-region)
  ;; ------------------
  (leaf expand-region
    :doc "Increases the selected region by semantic units"
    :url "https://github.com/magnars/expand-region.el"
    :bind
    (("C-=" . er/expand-region)
     ("C--" . er/contract-region)))
#+end_src

**** Git
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'magit)
  ;; ------------------
  (leaf magit
    :doc "Magit is an interface to the version control system Git"
    :url "https://github.com/magit/magit"
    :custom
    (tramp-ssh-controlmaster-options . "")
    :bind ("C-x g s" . magit-status))
#+end_src

**** Modal
#+begin_src emacs-lisp :tangle no
  ;; ------------------
  (straight-use-package 'meow)
  ;; ------------------
  (leaf meow
    :doc "Modular Emacs On Wish"
    :url "https://github.com/DogLooksGood/meow"
    :require meow init-meow-setup
    :custom
    (meow-visit-sanitize-completion  . nil)
    (meow-esc-delay                  . 0.001)
    (meow-select-on-change           . t)
    (meow-cursor-type-normal         . 'box)
    (meow-cursor-type-insert         . 'bar)
    (meow-cursor-type-keypad         . 'hbox)
    (meow-selection-command-fallback . '((meow-replace . meow-page-up)
                                         (meow-change  . meow-change-char)
                                         (meow-save    . meow-save-empty)
                                         (meow-kill    . meow-C-k)
                                         (meow-cancel  . keyboard-quit)
                                         (meow-pop     . meow-pop-grab)
                                         (meow-delete  . meow-C-d)))
    :init
    (meow-global-mode t)
    :config
    (progn
      (meow-esc-mode 1)
      (meow-setup)))
#+end_src

**** MoveText
#+begin_src emacs-lisp :tangle no
  ;; ------------------
  (straight-use-package 'move-text)
  ;; ------------------
  (leaf move-text
    :doc "allows you to move the current line, if a region is marked, it will move the region instead"
    :url "https://github.com/emacsfodder/move-text"
    :init
    (move-text-default-bindings))
#+end_src

**** NeoTree
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'neotree)
  ;; ------------------
  (leaf neotree
    :doc "A Emacs tree plugin like NerdTree for Vim"
    :url "https://github.com/jaypei/emacs-neotree"
    :custom
    (neo-theme . 'arrow)
    :config
    (progn
      (setq neo-theme (if (display-graphic-p) 'icons 'arrow)))
    :hook (neotree-mode-hook . hl-line-mode)
    :bind
    (("<f1>"   . neotree-toggle)
     ("<M-f1>" . neotree-dir)))
#+end_src

**** Parenthesis:
***** rainbow
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'rainbow-delimiters)
  ;; ------------------
  (leaf rainbow-delimiters
    :doc "Highlights delimiters according to their depth"
    :url "https://github.com/Fanael/rainbow-delimiters"
    :hook ((prog-mode-hook) . rainbow-delimiters-mode))
#+end_src

***** electric-pair
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  ;; ------------------
  (leaf electric
    :doc "Electrify things."
    :tag "built-in"
    :init
    (show-paren-mode      t)
    (electric-pair-mode   t)
    (electric-indent-mode t)
    (electric-quote-mode  nil)
    :custom
    (electric-quote-context-sensitive   . t)
    (electric-quote-paragraph           . t)
    (electric-quote-string              . nil)
    (electric-quote-replace-double      . t)
    (show-paren-style                   . 'parenthesis)
    (show-paren-when-point-in-periphery . nil)
    (show-paren-when-point-inside-paren . nil)
    (electric-pair-preserve-balance     . t)
    (electric-pair-skip-whitespace      . nil)
    (electric-pair-skip-self . 'electric-pair-default-skip-self)
    (electric-pair-skip-whitespace-chars . '(9 10 32))
    (electric-pair-pairs . '((34   . 34)
                             (8216 . 8217)
                             (8220 . 8221)
                             (171  . 187))))
#+end_src

***** lispy
#+begin_src emacs-lisp :tangle no
  ;; ------------------
  (straight-use-package 'lispy)
  ;; ------------------
  (leaf lispy
    :doc "A popular method to navigate and edit LISP code in Emacs"
    :url "https://github.com/abo-abo/lispy"
    :disabled t
    :hook
    (emacs-lisp-mode-hook
     scheme-mode-hook
     lisp-mode-hook
     sly-mode-hook
     clojure-mode-hook
     cider-mode-hook))
#+end_src

**** Projects
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'projectile)
  ;; ------------------
  (leaf projectile
    :doc "Projectile is a project interaction library for Emacs."
    :url ""
    :custom
    (projectile-switch-project-action . 'projectile-dired)
    :bind (:projectile-mode-map
           ("C-c p" . projectile-command-map))
    :init (projectile-mode 1))

  (leaf project
    :doc "Gnu Emacs project management"
    :tag "built-in"
    :custom
    (project-list-file . rx:projects-d))
#+end_src

**** Scroll
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'sublimity)
  (straight-use-package 'yascroll)
  ;; ------------------
  (leaf sublimity
    :doc "Smooth-scrolling, minimap and distraction-free mode"
    :url "https://github.com/zk-phi/sublimity"
    :custom
    (hscroll-margin                  . 1)
    (hscroll-step                    . 1)
    (scroll-conservatively           . 101)
    (scroll-margin                   . 6)
    (scroll-preserve-screen-position . t)
    :init (sublimity-mode t))

  (leaf yascroll
    :doc "Yet Another Scroll Bar Mode"
    :url "https://github.com/emacsorphanage/yascroll"
    :init (global-yascroll-bar-mode t))
#+end_src

**** Teminals
***** ansi-term
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'xterm-color)
  ;; ------------------
#+end_src

***** eshell
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'eshell-fringe-status)
  ;; ------------------
  (setenv "PAGER" "cat")

  ;; Save command history when commands are entered
  (add-hook 'eshell-pre-command-hook 'eshell-save-some-history)

  (add-hook 'eshell-before-prompt-hook
            (lambda ()
              (setq xterm-color-preserve-properties t)))

  (setq eshell-prompt-function
        (lambda ()
          (concat (format-time-string "%Y-%m-%d %H:%M" (current-time))
                  (if (= (user-uid) 0) " # " " λ "))))

  (setq eshell-directory-name (concat rx:temp-d "eshell/")
        eshell-aliases-file   (concat eshell-directory-name "aliases"))

  (custom-set-variables
   '(eshell-prompt-regexp                    "^[^λ]+ λ ")
   '(eshell-history-size                     1024)
   '(eshell-buffer-maximum-lines             10000)
   '(eshell-hist-ignoredups                  t)
   '(eshell-highlight-prompt                 t)
   '(eshell-prefer-lisp-functions            nil)
   '(eshell-scroll-to-bottom-on-input        'all)
   '(eshell-error-if-no-glob                 t)
   '(eshell-destroy-buffer-when-process-dies t))

  (defun +rx/eshell/clear ()
    "Clear the eshell buffer."
    (let ((inhibit-read-only t))
      (erase-buffer)
      (eshell-send-input)))

  (add-hook 'eshell-mode-hook
            (lambda ()
              (add-to-list 'eshell-visual-commands "ssh")
              (add-to-list 'eshell-visual-commands "tail")
              (add-to-list 'eshell-visual-commands "top")
              ;; Aliases
              (eshell/alias "clear" "+rx/eshell/clear")))

  (add-hook 'eshell-mode-hook 'eshell-fringe-status-mode)
#+end_src

***** vterm
#+begin_src emacs-lisp :tangle no
  ;; ------------------
  (straight-use-package 'vterm)
  ;; ------------------
  (leaf vterm
    :doc ""
    :url ""
    :disabled t
    :require vterm)
#+end_src

***** shell-pop
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'shell-pop)
  ;; ------------------
  (leaf shell-pop
    :doc "Helps you to use shell easily on Emacs"
    :url "https://github.com/kyagi/shell-pop-el"
    :custom
    (shell-pop-cleanup-buffer-at-process-exit . t)
    (shell-pop-term-shell                     . "/run/current-system/sw/bin/zsh")
    (shell-pop-window-position                . "bottom")
    (shell-pop-window-size                    . 40)
    (shell-pop-shell-type                     . '("ansi-term" "*ansi-term*" (lambda ()
                                                                              (ansi-term shell-pop-term-shell))))
    :config
    (progn
      (shell-pop--set-shell-type 'shell-pop-shell-type shell-pop-shell-type))
    :bind
    ("<C-return>" . shell-pop))
#+end_src

**** Transient
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'transient)
  ;; ------------------
  (leaf transient
    :doc "An infix arguments and suffix commands"
    :url "https://github.com/magit/transient"
    :custom
    (transient-values-file      . rx:cache-d)
    (transient-default-level    . 5)
    (transient-mode-line-format . nil))
#+end_src

**** Undo-Tree
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'undo-tree)
  ;; ------------------
  (leaf undo-tree
    :doc ""
    :url ""
    :init (global-undo-tree-mode)
    :custom
    (undo-tree-visualizer-timestamps . t)
    (undo-tree-visualizer-diff       . t))
#+end_src

**** Wich-Key
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'which-key)
  ;; ------------------
  (leaf which-key
    :doc "Displays the keybindings following your currently entered incomplete command in a popup"
    :url "https://github.com/justbur/emacs-which-key"
    :custom
    (which-key-idle-delay           . 0.5)
    (which-key-show-early-on-C-h    . t)
    (which-key-show-major-mode      . t)
    (which-key-popup-type           . 'side-window)
    (which-key-side-window-location . 'bottom)
    (which-key-sort-order           . 'which-key-local-then-key-order)
    :init (which-key-mode))
#+end_src

*** Window Manager
**** Dmenu
#+begin_src emacs-lisp :tangle no
  ;; ------------------
  (straight-use-package 'dmenu)
  ;; ------------------
  (leaf dmenu
    :doc ""
    :url ""
    :bind ("s-d" . dmenu))
#+end_src

**** Exwm
#+begin_src emacs-lisp :tangle no
  ;; ------------------
  (straight-use-package 'exwm)
  ;; ------------------
  (leaf exwm
    :doc "EXWM (Emacs X Window Manager)"
    :url "https://github.com/ch11ng/exwm"
    ;; :when (display-graphic-p)
    :require
    (exwm-config exwm-randr)
    :custom
    (exwm-workspace-number                . 3)
    (exwm-layout-show-all-buffers         . t)
    (exwm-randr-workspace-monitor-plist   . '(0 "eDP-1" 1 "HDMI-1"))

    ;; meow support
    (exwm-input-global-keys . `(([?\s-x]  . meow-keypad-start)
                                ([?\s-m]  . meow-keypad-start)
                                ([?\s-g]  . meow-keypad-start)
                                ([?\s-c]  . meow-keypad-start)
                                ([?\s-\ ] . ,meow-leader-keymap)))

    ;; mimic keys
    (exwm-input-simulation-keys . '(
                                    ;; movement
                                    ([?\C-b] . [left])
                                    ([?\M-b] . [C-left])
                                    ([?\C-f] . [right])
                                    ([?\M-f] . [C-right])
                                    ([?\C-p] . [up])
                                    ([?\C-n] . [down])
                                    ([?\C-a] . [home])
                                    ([?\C-e] . [end])
                                    ([?\M-v] . [prior])
                                    ([?\C-v] . [next])
                                    ([?\C-d] . [delete])
                                    ([?\C-k] . [S-end delete])
                                    ;; cut/paste.
                                    ([?\C-w] . [?\C-x])
                                    ([?\M-w] . [?\C-c])
                                    ([?\C-y] . [?\C-v])
                                    ;; search
                                    ([?\C-s] . [?\C-f])))
    :init
    (exwm-enable)
    :hook
    (exwm-randr-screen-change-hook
     . (lambda ()
         (start-process-shell-command
          "xrandr" nil "xrandr --output eDP-1 --right-of HDMI-1 --auto")))
    :config
    (progn
      (exwm-randr-enable)
      ;; this is a way to declare truly global/always working keybindings
      (exwm-input-set-key (kbd "s-r") 'exwm-reset)
      (exwm-input-set-key (kbd "s-k") 'exwm-workspace-delete)
      (exwm-input-set-key (kbd "s-w") 'exwm-workspace-swap)

      ;; the next loop will bind s-<number> to switch to the corresponding workspace
      (dotimes (i 4)
        (exwm-input-set-key (kbd (format "s-%d" i))
                            `(lambda ()
                              (interactive)
                              (exwm-workspace-switch-create ,i))))

      ;; the simplest launcher, I keep it in only if dmenu eventually stopped working or something
      (exwm-input-set-key (kbd "s-&")
                          (lambda (command)
                            (interactive (list (read-shell-command "$ ")))
                            (start-process-shell-command command nil command)))

      ;; an easy way to make keybindings work *only* in line mode
      (push ?\C-q exwm-input-prefix-keys)
      (define-key exwm-mode-map [?\C-q] 'exwm-input-send-next-key)



      ;; this little bit will make sure that XF86 keys work in exwm buffers as well
      (dolist (k '(XF86AudioLowerVolume
                   XF86AudioRaiseVolume
                   XF86PowerOff
                   XF86AudioMute
                   XF86AudioPlay
                   XF86AudioStop
                   XF86AudioPrev
                   XF86AudioNext
                   XF86ScreenSaver
                   XF68Back
                   XF86Forward
                   Scroll_Lock
                   print))
        (cl-pushnew k exwm-input-prefix-keys))))
#+end_src

**** Moving Around
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (leaf windmove
    :doc "Move between windows"
    :tag "built-in"
    :setq
    (windmove-wrap-around . t)
    :bind
    (("M-o"       . other-window)
     ("<M-left>"  . windmove-left)
     ("<M-up>"    . windmove-up)
     ("<M-down>"  . windmove-down)
     ("<M-right>" . windmove-right)
     ("C-c w h"   . windmove-left)
     ("C-c w j"   . windmove-down)
     ("C-c w k"   . windmove-up)
     ("C-c w l"   . windmove-right)))
#+end_src

**** Resizing
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'windresize)
  ;; ------------------
  (leaf windresize
    :doc "Self explanatory"
    :url "http://elpa.gnu.org/packages/windresize.html"
    :bind ("C-c w r" . windresize))
#+end_src

**** Shackle
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'shackle)
  ;; ------------------
  (leaf shackle
    :doc ""
    :url ""
    :custom
    (shackle-lighter           . "")
    (shackle-default-alignment . 'below)
    (shackle-default-size      . 0.4)
    (shackle-rules
     . '((help-mode               :align above :size 0.25 :select t)
         (helpful-mode            :align above)
         (compilation-mode        :select t    :size 0.25)
         ("*Async Shell Command*" :ignore t)
         ("*compilation*"         :select t    :size 0.25)
         ("*Flycheck errors*"     :select t    :size 0.25)
         ("*Warnings*"            :select t    :size 0.25)
         ("*Error*"               :select t    :size 0.25)
         ("*Org Links*"           :select t    :size 0.25)
         ("*eshell*"              :align below :size 0.5   :popup t)
         ("*nixos-options-doc*"   :align below :size 0.25)
         (magit-status-mode       :align below :size 0.5   :inhibit-window-quit t)
         (magit-log-mode          :same t                  :inhibit-window-quit t)
         (magit-commit-mode       :ignore t)
         (magit-diff-mode         :select nil  :align left :size 0.5)
         (git-commit-mode         :same t)
         (vc-annotate-mode        :same t)))
    :init
    (shackle-mode t))
#+end_src

**** Splitting
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (defun split-and-follow-horizontally ()
    (interactive)
    (split-window-below)
    (balance-windows)
    (other-window 1))
  (global-set-key (kbd "C-x 2") 'split-and-follow-horizontally)

  (defun split-and-follow-vertically ()
    (interactive)
    (split-window-right)
    (balance-windows)
    (other-window 1))
  (global-set-key (kbd "C-x 3") 'split-and-follow-vertically)
#+end_src

** CODE
*** Langs
**** lisp
***** TODO clojure
***** TODO common-lisp
#+begin_src emacs-lisp :tangle no
  ;; ------------------
  (straight-use-package 'sly)
  ;; ------------------
  (leaf sly
    :doc ""
    :url "")
#+end_src

***** TODO elisp
***** scheme
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'geiser)
  ;; ------------------
  (leaf geiser
    :doc "Scheme interpreters to keep the Lisp Machine Spirit alive"
    :url "http://www.nongnu.org/geiser/"
    :custom
    (geiser-repl-history-filename  . rx:temp-d))
#+end_src

**** webdev
***** emmet
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'emmet-mode)
  ;; ------------------
  (leaf emmet-mode
    :doc "Support Emmet's feature set - no longer maintained?"
    :url "https://github.com/smihica/emmet-mode"
    :custom
    (emmet-insert-flash-time         . 0.1)
    (emmet-move-cursor-between-quote . t)
    (emmet-insert-flash-time . 0.001) ; effectively disabling it
    :config
    (add-hook 'js-jsx-mode-hook (lambda ()
                                  (setq-local emmet-expand-jsx-className? t)))
    (add-hook 'web-mode-hook    (lambda ()
                                  (setq-local emmet-expand-jsx-className? t)))
    :bind (:emmet-mode-keymap
           ("M-e" . emmet-expand-line))
    :hook (css-mode-hook
           html-mode-hook
           js-mode-hook js-jsx-mode-hook
           typescript-mode-hook web-mode-hook))
#+end_src

***** javascript
#+begin_src emacs-lisp :tangle no
  ;; ------------------
  (straight-use-package 'typescript-mode)
  (straight-use-package 'deno-fmt)
  ;; ------------------
  (leaf typescript-mode
    :doc "Editing Typescript-files in GNU Emacs"
    :url "https://github.com/emacs-typescript/typescript.el"
    :mode
    (("\\.[tj]s\\'"  . typescript-mode)
     ("\\.[tj]sx\\'" . typescript-mode))
    :interpreter (deno) ;; (node)
    :hook
    (typescript-mode-hook . eglot-ensure))

  (leaf deno-fmt
    :doc "Formats the current buffer on save with deno fmt"
    :url "https://github.com/rclarey/deno-emacs"
    :bind
    (:typescript-mode-map
     ("C-c d f" . deno-fmt)))
#+end_src

***** purescript
#+begin_src emacs-lisp :tangle no
  ;; ------------------
  (straight-use-package 'purescript-mode)
  (straight-use-package 'psc-ide)
  ;; ------------------
  (leaf purescript-mode
    :doc "PureScript mode package for Emacs"
    :url ""
    :mode ("\\.purs\\'"))

  (leaf psc-ide
    :doc ""
    :url ""
    :hook
    (purescript-mode-hook . (lambda ()
                              (psc-ide-mode)
                              (flycheck-mode)
                              (turn-on-purescript-indentation))))
#+end_src

***** vue
#+begin_src emacs-lisp :tangle no
  ;; ------------------
  ;; (straight-use-package 'vue-mode)
  ;; ------------------
  ;; (leaf vue-mode
  ;;   :doc ""
  ;;   :url ""
  ;;   :require
  ;;   (vue-mode web-mmode)
  ;;   :custom
  ;;   (mmm-submode-decoration-level . 0)
  ;;   :init
  ;;   (progn
  ;;     (define-derived-mode rx-vue-mode web-mode "rxVue"
  ;;       "A major mode derived from web-mode, for editing .vue files with LSP support.")
  ;;     (add-to-list 'auto-mode-alist '("\\.vue\\'" . rx-vue-mode)))
  ;;   :mode
  ;;   ("\\.vue\\'" . vue-mode)
  ;;   :hook
  ;;   (rx-vue-mode . eglot-ensure))
#+end_src

***** web-mode
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'web-mode)
  ;; ------------------
  (leaf web-mode
    :doc "An autonomous emacs major-mode for editing web templates."
    :url "https://web-mode.org/"
    :custom
    (web-mode-code-indent-offset                 . 2)
    (web-mode-css-indent-offset                  . 2)
    (web-mode-markup-indent-offset               . 2)
    (web-mode-enable-auto-indentation            . t)
    (web-mode-enable-auto-pairing                . t)
    (web-mode-enable-auto-closing                . t)
    (web-mode-enable-auto-quoting                . t)
    (web-mode-enable-current-column-highlight    . t)
    (web-mode-enable-current-element-highlight   . t)
    (web-mode-enable-html-entities-fontification . t)
    ;; (web-mode-content-types-alist . '(("jsx" . "\\.js[x]?\\'")))
    :mode
    ("\\.html?\\'"
     "\\.jsx\\'"
     "\\.tsx\\'"
     "\\.ejs\\'"
     "\\.hbs\\'"
     "\\.json\\'"))
#+end_src

**** TODO haskell
**** lua
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'lua-mode)
  ;; ------------------
  (leaf lua-mode
    :doc ""
    :url "https://github.com/immerrr/lua-mode"
    :mode
    ("\\.lua$\\’")
    :interpreter lua)
#+end_src

**** nix
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'nix-mode)
  (straight-use-package 'helm-nixos-options)
  ;; ------------------
  (leaf nix-mode
    :doc "An Emacs major mode for editing Nix expressions"
    :url "https://github.com/NixOS/nix-mode"
    :mode ("\\.nix\\'" . nix-mode)
    :hook (nix-mode-hook . eglot-ensure))

  (leaf helm-nixos-options
    :doc "A set of useful Emacs modes and functions for users of Nix and NixOS"
    :url "https://github.com/travisbhartwell/nix-emacs"
    :config
    (progn
      (setq flycheck-command-wrapper-function
            (lambda (cmd)
              (apply 'nix-shell-command (nix-current-sandbox) cmd))
            flycheck-executable-find
            (lambda (cmd)
              (nix-executable-find (nix-current-sandbox) cmd))))
    :bind
    ("C-c h n" . helm-nixos-options))
#+end_src

**** TODO python
**** perl
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'cperl-mode)
  ;; ------------------
  (leaf cperl-mode
    :doc ""
    :url ""
    :mode
    ("\\.\\([pP][Llm]\\|al\\)\\'" . cperl-mode)
    :setq
    (cperl-indent-level               . 3)
    (cperl-close-paren-offset         . -3)
    (cperl-continued-statement-offset . 3)
    (cperl-indent-parens-as-block     . t)
    (cperl-tab-always-indent          . t))
#+end_src

**** TODO r
*** Modes
**** sh-script
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  ;; ------------------
  (leaf sh-script
    :doc ""
    :tag "built-in"
    :mode ("\\.sh\\’" . sh-mode)
    :hook (shell-script-mode . eglot-ensure))
#+end_src

**** csv
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'csv-mode)
  ;; ------------------
  (leaf csv-mode
    :doc ""
    :url ""
    :mode ("\\.[cC][sS][vV]\\'" . csv-mode)
    :setq
    (csv-separators . '("," ";" "|" " ")))
#+end_src

**** dhall
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'dhall-mode)
  ;; ------------------
  (leaf dhall-mode
    :doc ""
    :url ""
    :mode
    ("\\.dhall\\'" . dhall-mode))
#+end_src

**** json
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'json-mode)
  ;; ------------------
  (leaf json-mode
    :doc ""
    :url ""
    :mode ("\\.json\\'" . json-mode))
#+end_src

**** markdown
#+begin_src emacs-lisp :tangle no

#+end_src

**** yaml
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'yaml-mode)
  ;; ------------------
  (leaf yaml-mode
    :doc ""
    :url ""
    :mode
    ("\\.yaml\\'" . yaml-mode))
#+end_src

*** Syntax
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'flycheck)
  ;; ------------------
  (leaf flycheck
    :doc "A modern on-the-fly syntax checking extension"
    :url "https://www.flycheck.org/en/latest/"
    :setq
    (flycheck-highlighting-mode . 'line)
    :config
    (progn
      (define-fringe-bitmap 'my-flycheck-fringe-indicator
        (vector #b00000000
                #b00000000
                #b00000000
                #b00000000
                #b00000000
                #b00000000
                #b00000000
                #b00011100
                #b00111110
                #b00111110
                #b00111110
                #b00011100
                #b00000000
                #b00000000
                #b00000000
                #b00000000
                #b00000000))

      (flycheck-define-error-level 'error
        :severity 2
        :overlay-category 'flycheck-error-overlay
        :fringe-bitmap 'my-flycheck-fringe-indicator
        :fringe-face 'flycheck-fringe-error)

      (flycheck-define-error-level 'warning
        :severity 1
        :overlay-category 'flycheck-warning-overlay
        :fringe-bitmap 'my-flycheck-fringe-indicator
        :fringe-face 'flycheck-fringe-warning)

      (flycheck-define-error-level 'info
        :severity 0
        :overlay-category 'flycheck-info-overlay
        :fringe-bitmap 'my-flycheck-fringe-indicator
        :fringe-face 'flycheck-fringe-info))
    :bind (("C-c e n" . flycheck-next-error)
           ("C-c e p" . flycheck-previous-error)))
#+end_src

**** flymake
#+begin_src emacs-lisp :tangle no
  ;; ------------------
#+end_src

**** flyspell
** ORG
*** org-mode
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  ;; ------------------
  (leaf org
    :doc ""
    :tag ""
    :require (ox ob-js)
    :custom
    (org-directory                     . rx:org-d)
    ;; general settings
    (org-startup-with-inline-images    . (display-graphic-p))
    (org-startup-align-all-tables      . t)
    (org-use-speed-commands            . t)
    (org-use-fast-todo-selection       . 'expert)
    (org-fast-tag-selection-single-key . 'expert)
    (org-hide-emphasis-markers         . t)
    (org-adapt-indentation             . t)
    (org-confirm-babel-evaluate        . t)
    (org-pretty-entities               . t)
    (org-support-shift-select          . t)
    ;; src blocks
    (org-edit-src-content-indentation  . 2)
    (org-src-tab-acts-natively         . t)
    (org-src-fontify-natively          . t)
    (org-src-preserve-indentation      . nil)
    (org-src-window-setup              . 'current-window)
    (org-src-strip-leading-and-trailing-blank-lines . t)
    ;; modules
    (org-modules . '(org-crypt
                     org-habit
                     org-tempo
                     org-protocol))
    ;; keywords
    (org-todo-keywords
     . '((sequence "IDEA(i)" "TODO(t)" "STARTED(s)" "NEXT(n)" "WAITING(w)" "|" "DONE(d)")
         (sequence "|" "CANCELED(c)" "DELEGATED(l)" "SOMEDAY(f)")))
    :config
    (progn
      (org-babel-do-load-languages
       'org-babel-load-languages '((emacs-lisp . t)
                                   (shell      . t)
                                   (js         . t)
                                   (scheme     . t)
                                   (dot        . t))))
    :hook
    ((org-mode-hook . org-indent-mode)
     (org-mode-hook . auto-fill-mode)))
#+end_src

*** org-capture
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  ;; ------------------
  (leaf org-capture
    :doc ""
    :url ""
    :bind ("C-c o c" . org-capture)
    :config
    (with-eval-after-load 'org-capture
      (setq denote-org-capture-specifiers "%l\n%i\n%?")
      (add-to-list 'org-capture-templates
                   '("n" "New note (with denote.el)" plain
                     (file denote-last-path)
                     #'denote-org-capture
                     :no-save t
                     :immediate-finish nil
                     :kill-buffer t
                     :jump-to-captured t))))
#+end_src

*** org-superstar
#+begin_src emacs-lisp :tangle no
  ;; ------------------
  (straight-use-package 'org-superstar)
  ;; ------------------
  (leaf org-superstar
    :doc ""
    :url ""
    :custom
    (org-superstar-headline-bullets-list
     ;; . '("☰" "☷" "☵" "☲"  "☳" "☴"  "☶"  "☱")
     . '("*" "**" "***" "****" "*****" "******" "*******" "********"))
    (org-superstar-leading-bullet . " ")
    :hook (org-mode-hook . org-superstar-mode))
#+end_src

*** org-toc
#+begin_src emacs-lisp :tangle no
  ;; ------------------
  (straight-use-package 'toc-org)
  ;; ------------------
  (leaf toc-org
    :doc ""
    :url "https://github.com/snosov1/toc-org"
    :after org
    :hook
    (org-mode-hook . toc-org-mode))
#+end_src

** OTHERS
*** Academic
**** Export
#+begin_src emacs-lisp :tangle no
  ;; ------------------
  (straight-use-package 'ox-epub)
  ;; ------------------
  (leaf ox-epub
    :doc ""
    :url ""
    :after org)

  (leaf ox-latex
    :doc "FIX: use org-reload before try to export. (why?)"
    :tag "built-in"
    :after org
    :custom
    (org-latex-default-figure-position . "H")
    (org-latex-listings                . t)
    (org-latex-listings                . 'minted)
    (org-latex-pdf-process
     . '("latexmk -shell-escape -bibtex -f -pdf %f")))
#+end_src

**** TODO Presentation
#+begin_src emacs-lisp :tangle no
  ;; ------------------
  ;; (straight-use-package ')
  ;; ------------------
#+end_src

**** References
***** bibtex
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package 'helm-bibtex)
  ;; ------------------
  (leaf bibtex
    :doc "Manage bib references"
    :tag "built-in"
    :custom
    (bibtex-set-dialect . 'biblatex))

  (leaf helm-bibtex
    :doc "Allow you to search and manage your BibTeX bibliography"
    :url "https://github.com/tmalsburg/helm-bibtex"
    :custom
    (bibtex-completion-pdf-field    . "file")
    (bibtex-completion-pdf-symbol   . "⌘")
    (bibtex-completion-notes-symbol . "✎")
    (bibtex-completion-library-path . '("~/Library"))
    (bibtex-completion-bibliography . '("~/Library/references.bib"))
    (bibtex-completion-notes-path   . '("~/Library/notes")))
#+end_src

***** citar
#+begin_src emacs-lisp :tangle yes
  ;; ------------------
  (straight-use-package
   '(citar :type git
           :host github
           :repo "emacs-citar/citar"
           :includes (citar-org)))
  ;; ------------------

  (leaf citar
    :doc "BibTeX, BibLaTeX, and CSL JSON bibliographic data, and LaTeX, markdown, and org-cite editing support."
    :url "https://github.com/bdarcus/citar"
    :custom
    (org-cite-global-bibliography . '("~/Documents/Zotero/exports/ref.bib"))
    (citar-bibliography           . org-cite-global-bibliography)
    (org-cite-export-processor    . '((latex . (csl "associacao-brasileira-de-normas-tecnicas.csl"))
                                      (md    . (csl "associacao-brasileira-de-normas-tecnicas.csl"))
                                      (odt   . (csl "associacao-brasileira-de-normas-tecnicas.csl"))
                                      (t     . (csl "modern-language-association.cls"))
                                      ;; (latex . biblatex)
                                      ))
    :bind
    (("C-c x c" . citar-insert-citation)
     ("C-c x r" . citar-insert-reference)
     ("C-c x n" . citar-open-note)
     (:minibuffer-local-map
      ("M-b" . citar-insert-preset))))

  (leaf citar-org
    :after oc
    :custom
    (org-cite-insert-processor    . 'citar)
    (org-cite-follow-processor    . 'citar)
    (org-cite-activate-processor  . 'citar))
#+end_src

***** org-ref
#+begin_src emacs-lisp :tangle no
  ;; ------------------
  (straight-use-package 'org-ref)
  ;; ------------------
  (leaf org-ref
    :doc "Citations, cross-references, indexes, glossaries and bibtex utilities for org-mode"
    :url "https://github.com/jkitchin/org-ref"
    :require
    (org-ref-helm
     org-ref-arxiv
     org-ref-pdf
     org-ref-bibtex
     org-ref-isbn
     org-ref-pubmed
     org-ref-url-utils
     doi-utils)
    :custom
    (org-ref-insert-link-function  . 'org-ref-insert-link-hydra/body)
    (org-ref-insert-cite-function  . 'org-ref-cite-insert-helm)
    (org-ref-insert-label-function . 'org-ref-insert-label-link)
    (org-ref-insert-ref-function   . 'org-ref-insert-ref-link)
    (org-ref-cite-onclick-function . (lambda (_) (org-ref-citation-hydra/body)))
    :bind
    ("C-c C-]" . 'org-ref-insert-link-hydra/body))
#+end_src

*** Epub/Pdf
#+begin_src emacs-lisp :tangle no
  ;; ------------------
  (straight-use-package 'nov)
  (straight-use-package 'pdf-tools)
  ;; ------------------
  (leaf nov
    :doc ""
    :url ""
    :require nov
    :mode ("\\.epub\\'" . nov-mode)
    :custom
    (nov-text-width . 72)
    :hook (nov-mode-hook
           . (lambda ()
               (face-remap-add-relative
                'variable-pitch :family "Liberation Serif" :height 1.2))))

  (leaf pdf-tools
    :doc ""
    :url ""
    ;; :disabled t
    :require pdf-tools
    :init
    (pdf-tools-install t t t)
    :custom
    (pdf-view-midnight-colors     . '("white smoke" . "gray5"))
    (pdf-misc-print-programm-args . '("-o media=A4" "-o fitplot"))
    (pdf-view-display-size        . 'fit-page))
#+end_src

*** Denote
#+begin_src emacs-lisp :tangle yes
    ;; ------------------
    (straight-use-package
     '(denote :type   git
              :host   github
              :branch "main"
              :repo   "protesilaos/denote"))
    ;; ------------------
    (leaf denote
      :doc ""
      :url ""
      :require (denote-dired denote-org-capture)
      :hook ((find-file-hook . denote-link-buttonize-buffer)
             (dired-mode-hook . denote-dired-mode))
      :custom
      (denote-directory . "~/Library/notes") ; prefer to use .dir-locals.el file.
      (denote-known-keywords . '("biology" "politics" "economics" "nixos" "emacs"))
      (denote-file-type . nil)
      :bind
      (("C-c n j" . my-denote-journal)
       ("C-c n n" . denote)
       ("C-c n N" . denote-type)
       ("C-c n d" . denote-date)
       ("C-c n s" . denote-subdirectory)
       ("C-c n i" . denote-link)
       ("C-c n I" . denote-link-add-links)
       ("C-c n l" . denote-link-find-file)
       ("C-c n b" . denote-link-backlinks)
       ("C-c n r" . denote-dired-rename-file)))

    (defun my-denote-journal ()
      "Create an entry tagged ‘journal’, while prompting for a title."
      (interactive)
      (denote
       (denote--title-prompt) '("journal")))
#+end_src

*** GkRoam
#+begin_src emacs-lisp :tangle no
  ;; ------------------
  (straight-use-package
   '(gkroam :type   git
            :host   github
            :branch "develop"
            :repo   "Kinneyzhang/gkroam"))
  ;; ------------------
  (leaf gkroam
    :doc "A lightweight Roam Research replica"
    :url "https://github.com/Kinneyzhang/gkroam"
    :require gkroam
    :custom
    (gkroam-root-dir             . "~/Nextcloud/org/gkroam")
    (gkroam-prettify-page-p      . t)
    (gkroam-show-brackets-p      . t)
    (gkroam-use-default-filename . t)
    (gkroam-window-margin        . 0)
    (gkroam-title-height         . 200)
    :hook
    (after-init-hook . gkroam-mode)
    :bind
    (:gkroam-mode-map
     (("C-c r I" . gkroam-index)
      ("C-c r d" . gkroam-daily)
      ("C-c r D" . gkroam-delete)
      ("C-c r f" . gkroam-find)
      ("C-c r i" . gkroam-insert)
      ("C-c r n" . gkroam-dwim)
      ("C-c r e" . gkroam-link-edit)
      ("C-c r u" . gkroam-show-unlinked)
      ("C-c r p" . gkroam-toggle-prettify)
      ("C-c r t" . gkroam-toggle-brackets)
      ("C-c r R" . gkroam-rebuild-caches)
      ("C-c r g" . gkroam-update))))
#+end_src

** FOOTER
#+begin_src emacs-lisp :tangle yes
  ;; config.el ends here.
#+end_src

* REFERENCES
** LITERATE
- https://github.com/hlissner/doom-emacs

** MODULAR
- https://github.com/DogLooksGood/dogEmacs

** SINGLE
- https://github.com/olivertaylor/dotfiles/tree/2bd57060c6823712ecaa08748aca910289c9cfb8/emacs



